package com.zone.sdk.isd.util;

/**
 * @Author: pkqlqx
 * @CreateDate: 2021/12/14 14:30
 * @Description:
 */
public class ColorUtil {

    public static void transform(int[] pixels, int oldColor, int newColor){
        for (int i = 0; i < pixels.length; i++) {
            if (pixels[i] == oldColor){
                pixels[i] = newColor;
            }
        }
    }

    public static int[] getRGB(int color) {
        int[] colors = new int[3];
        colors[0] = (color >> 16) & 0xFF;
        colors[1] = (color >> 8) & 0xFF;
        colors[2] = (color) & 0xFF;
        return colors;
    }

    public static int getRed(int color) {
        return (color >> 16) & 0xFF;
    }

    public static int getBlue(int color) {
        return (color) & 0xFF;
    }

    public static int getGreen(int color) {
        return (color >> 8) & 0xFF;
    }

    public static int getColor(int r, int g, int b) {
        return ((0xFF) << 24) |
                ((r & 0xFF) << 16) |
                ((g & 0xFF) << 8) |
                ((b & 0xFF));
    }

    public static int getColor(int[] rgb){
        return ((0xFF) << 24) |
                ((rgb[0] & 0xFF) << 16) |
                ((rgb[1] & 0xFF) << 8)  |
                ((rgb[2] & 0xFF));
    }
}
